home *** CD-ROM | disk | FTP | other *** search
- /* $Id: 3DCOFAIL.H 1.11 1997/04/14 23:20:37 TOM Exp $ */
- /*****************************************************************************\
- * *
- * 3DCoFail.h *
- * Failure handling for COM extensions *
- * *
- * Copyright (c) 1995, Ray Dream, Inc. All rights reserved. *
- * *
- \*****************************************************************************/
-
- #ifndef __3DCOFAIL__
- #define __3DCOFAIL__
-
- struct IShUtilities;
- struct IShActionManager;
- struct IShMenuManager;
- struct IShViewManager;
- struct IShSMPUtilities;
-
- /*****************************************************************************\
- * *
- * Utilities pointers *
- * *
- \*****************************************************************************/
- // gShellUtilities keeps a pointer on the Shell Utilities interface as given by
- // I3DExtension::ShellUtilitiesInit(). This is used as a convenient back-door
- // to the Shell. gShellUtilities is NULL by default, and is initialized by
- // InitCoFailure() (this is pretty much all what InitCoFailure() does).
- extern IShUtilities* gShellUtilities;
- extern IShActionManager* gActionManager;
- extern IShMenuManager* gMenuManager;
- extern IShViewManager* gViewManager;
- extern IShSMPUtilities* gShellSMPUtilities;
-
- /*****************************************************************************\
- * *
- * Failure Handling *
- * *
- \*****************************************************************************/
- // Initialize gShellUtilities. Must be called to have working failure handling
- void InitCoFailure(IShUtilities* shellUtilities);
-
- // Failure handling
- #ifdef qPowerPC
- typedef int jmp_buf[64];
- #else
- typedef int jmp_buf[16];
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- #if defined(_MAC) && !defined(_MSMAC)
- #define __cdecl
- #endif
-
- void FailNIL(void* apointer);
- void FailOSErr(short err);
-
- #ifdef __cplusplus
- }
- #endif
-
- #ifdef __cplusplus
-
- #define VOLATILE(a) ((void)&a)
- #define DECLAREVOLATILE(a,b) a volatile b;
-
- class FailInfo {
- public:
- jmp_buf savedState;
- short error;
- long message;
- FailInfo* nextInfo;
- public:
- FailInfo();
- inline void ReSignal();
- inline void Success();
- inline void Reset();
- inline short GetError();
- inline long GetMessage();
- };
- typedef FailInfo* FailInfoPtr;
-
- void __cdecl Failure(short error, long message);
-
- extern "C" {
- FailInfoPtr* __cdecl GetGTopHandler();
- typedef int (*RDsetjmpProc)(jmp_buf);
- extern RDsetjmpProc RDsetjmp;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FailInfo inline method definitions
- //----------------------------------------------------------------------------------------
-
- #define TRY(f) \
- f.nextInfo = *GetGTopHandler(), \
- (f.nextInfo ? (*GetGTopHandler() = &f, ((*RDsetjmp)(f.savedState)==0)) : 1)
-
- inline void FailInfo::Reset() {
- error = 0;
- message = 0;
- nextInfo = 0;
- }
-
- inline FailInfo::FailInfo() {
- }
-
- inline void FailInfo::ReSignal() {
- ::Failure(error, message);
- }
-
- inline void FailInfo::Success() {
- *GetGTopHandler() = nextInfo;
- }
-
- inline short FailInfo::GetError() {
- return error;
- }
-
- inline long FailInfo::GetMessage() {
- return message;
- }
-
- #endif /* __cplusplus */
-
- /*****************************************************************************\
- * *
- * Memory management *
- * *
- \*****************************************************************************/
-
- void* RDmalloc(unsigned long size);
- void* RDcalloc(unsigned long nmemb, unsigned long size);
- void* RDrealloc(void* ptr, unsigned long size);
- void RDfree(void* ptr);
-
- #endif
-
-